﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace FSM_Framework
{
    //public enum StateEnum
    //{
    //    Init,
    //    Idle,
    //    IdleWithAlarm,
    //    SetUp,
    //    Ready,
    //    Loading,
    //    Working,
    //    Unloading,
    //    Stopping,
    //    Paused,
    //}

    /// <summary>
    /// 状态
    /// </summary>
    public class BladeState:IEquatable<BladeState>
    {
        private BladeState(string stateName)
        {
            StateName = stateName;
        }

        public string StateName { get; set; }

        public static readonly BladeState Init = new BladeState(nameof(Init));
        public static readonly BladeState Idle = new BladeState(nameof(Idle));
        public static readonly BladeState IdleWithAlarm = new BladeState(nameof(IdleWithAlarm));
        public static readonly BladeState SetUp = new BladeState(nameof(SetUp));
        public static readonly BladeState Ready = new BladeState(nameof(Ready));
        public static readonly BladeState Loading = new BladeState(nameof(Loading));
        public static readonly BladeState Working = new BladeState(nameof(Working));
        public static readonly BladeState Unloading = new BladeState(nameof(Unloading));
        public static readonly BladeState Stopping = new BladeState(nameof(Stopping));
        public static readonly BladeState Paused = new BladeState(nameof(Paused));

        public static bool IsWorking(BladeState bladeState)
        {
            return bladeState == Loading || bladeState == Unloading || bladeState == Working;
        }

        /// <summary>Returns a string that represents the current object.</summary>
        /// <returns>A string that represents the current object.</returns>
        public override string ToString()
        {
            return StateName;
        }

        /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// <see langword="true" /> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false" />.</returns>
        public bool Equals(BladeState? other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }

            if (ReferenceEquals(this, other))
            {
                return true;
            }

            return StateName == other.StateName;
        }

        /// <summary>Determines whether the specified object is equal to the current object.</summary>
        /// <param name="obj">The object to compare with the current object.</param>
        /// <returns>
        /// <see langword="true" /> if the specified object  is equal to the current object; otherwise, <see langword="false" />.</returns>
        public override bool Equals(object? obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            if (ReferenceEquals(this, obj))
            {
                return true;
            }

            if (obj.GetType() != this.GetType())
            {
                return false;
            }

            return Equals((BladeState) obj);
        }

        /// <summary>Serves as the default hash function.</summary>
        /// <returns>A hash code for the current object.</returns>
        public override int GetHashCode()
        {
            return StateName.GetHashCode();
        }
    }



}
